<?php
namespace Api\Controller;

use Think\Controller;
class MyController extends Controller {

	public function refund(){
		    $map['wid'] = session('wid');
	        $wechat = M("Wechat")->where($map)->find();
	        $appid = $wechat['appid'];
	        $mch_id = $wechat['mch_id'];
	        $key = $wechat['partner_key'];
		        vendor('Weixinpay.WxPayJsApiPay');

			    $inputObj = new \WxPayRefund();
                $inputObj->SetOut_trade_no("2018031757999751");
                $inputObj->SetOut_refund_no("tk2018031757999751");
               // $inputObj->transaction_id="4200000073201803170050953572";
                $inputObj->SetTotal_fee("20");
                $inputObj->SetRefund_fee("20");
                $inputObj->SetOp_user_id($mch_id);
                 $inputObj->SetAppid($appid);
       			 $inputObj->SetMch_id($mch_id);

 			 try{
                  $wxorder = \WxPayApi::refund($inputObj, $key);
                  }catch(Exception $e){
                        $arr = array("err_code"=>400,"err_msg"=>$e->getMessage());
                        print_r($arr);
                   }	


                    if($wxorder['return_code'] == "FAIL"){
	            $arr = array("err_code"=>400,"err_msg"=>$wxorder['return_msg']);
	            print_r($arr);
        }

                   echo "请求发送成功";

               }
}